package chessman;
import java.util.ArrayList;

import javax.swing.ImageIcon;


public class Rook extends Chessman{

/**
	 * 
	 */
	private static final long serialVersionUID = 109230307668313527L;
private static Rook instanceA = new Rook(new ImageIcon("Resources/Images/Rook-icon.png"),0);
private static Rook instanceB = new Rook(new ImageIcon("Resources/Images/Rook-blue-icon.png"),1);
	public static Rook getInstanceTeamA(){
		return instanceA;
	}
	public static Rook getInstanceTeamB(){
		return instanceB;
	}
	public Rook(ImageIcon icon, int team) {
		super(icon,team);
		// TODO Auto-generated constructor stub
	}

	
	

	@Override
	public String toString() {
		return "Rook";
	}


	@Override
	public ArrayList<String> canMove(Chessman[] arrayChess) {
		// TODO Auto-generated method stub
		ArrayList<String> moves = new ArrayList<String>();
		String temp = null;
		Chessman c = null;
		for(int i=this.row+1;i<8;i++){
			c = arrayChess[i * 8 + this.col]; 
			if( c != null){ // co can duong
				if(this.isSameTeam(c)){ // cung team thi khong cho qua
					break;
				}
				else{ // khac team thi co the an len
					temp = this.cols[this.col]+this.rows[i];
					moves.add(temp);
					break;
				}
				
			}
			else{ // khong co can duong
				temp = this.cols[this.col]+this.rows[i];
				moves.add(temp);
			}
			
		}
		for(int i=this.row - 1;i >= 0;i--){
			c = arrayChess[i * 8 + this.col]; 
			if( c != null){ // co can duong
				if(this.isSameTeam(c)){ // cung team thi khong cho qua
					break;
				}
				else{ // khac team thi co the an len
					temp = this.cols[this.col]+this.rows[i];
					moves.add(temp);
					break;
				}
				
			}
			else{ // khong co can duong
				temp = this.cols[this.col]+this.rows[i];
				moves.add(temp);
			}
		}
		for(int i=this.col -1;i>=0;i--){
			c = arrayChess[this.row * 8 + i]; 
			if( c != null){ // co can duong
				if(this.isSameTeam(c)){ // cung team thi khong cho qua
					break;
				}
				else{ // khac team thi co the an len
					temp = this.cols[i]+this.rows[this.row];
					moves.add(temp);
					break;
				}
			}
			else{
				temp = this.cols[i]+this.rows[this.row];
				moves.add(temp);
			}
			
		}
		for(int i=this.col+1;i<8;i++){
			c = arrayChess[this.row * 8 + i]; 
			if( c != null){ // co can duong
				if(this.isSameTeam(c)){ // cung team thi khong cho qua
					break;
				}
				else{ // khac team thi co the an len
					temp = this.cols[i]+this.rows[this.row];
					moves.add(temp);
					break;
				}
			}
			else{
				temp = this.cols[i]+this.rows[this.row];
				moves.add(temp);
			}
		}
		return moves;
	}

	


	
	
	
}
